
#pragma once
#include "common.h"
#include "channel.h"

namespace srpc
{
    // Rpc Channel Client必须实现以下的方法
    template <class TChannel, class TFd>
    class RpcChannelClient
    {
    public:
        RpcChannelClient():mFd(-1) {}
        virtual ~RpcChannelClient() {}

        virtual void Close() = 0;
        virtual int Start() = 0;
        virtual int OpenChannel(std::string address, TChannel *rpcChannel) = 0;
    protected:
        TFd mFd;
    };

    class TcpRpcChannelClient : public RpcChannelClient<TcpRpcChannel, int>
    {
    public:
        TcpRpcChannelClient(EV_BASE ev_base) 
        {
           mpEvBase = ev_base;
        }
        virtual ~TcpRpcChannelClient() {}
        void Close();
        int Start();
        // 打开通道，就是给RocChannel设置一个套接字
        int OpenChannel(std::string address, TcpRpcChannel *rpcChannel);
    private:
        int constructConnection();
        int mServerPort;
        std::string mServerIP;
        EV_BASE mpEvBase;
    };
}